package com.lilicould.dao;

import com.lilicould.entity.Employee;
import com.lilicould.entity.EmployeeHasRole;
import com.lilicould.entity.EmployeeRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

public interface EmployeeDao {
    // 查询所有员工信息
    @Select("SELECT * FROM employee")
    ArrayList<Employee> selectAllEmployees();

    //通过员工ID获取员工信息
    @Select("SELECT * FROM employee WHERE employee_id = #{employeeId}")
    Employee selectEmployeeById(@Param("employeeId") String employeeId);

    // 通过员工ID获取员工-角色信息
    @Select("SELECT * FROM employee_has_role WHERE employee_id = #{employeeId}")
    ArrayList<EmployeeHasRole> selectEmployeeHasRoleByEmployeeId(@Param("employeeId") String employeeId);

    // 通过角色ID获取员工-角色信息
    @Select("SELECT * FROM employee_has_role WHERE role_id = #{roleId}")
    ArrayList<EmployeeHasRole> selectEmployeeHasRoleByRoleId(@Param("roleId") String roleId);

    // 通过角色ID获取角色信息
    @Select("SELECT * FROM employee_role WHERE role_id = #{roleId}")
    EmployeeRole selectEmployeeRoleById(@Param("roleId") String roleId);

    // 插入整个员工信息
    @Insert("INSERT INTO employee (employee_id, name, phone, salary) VALUES (#{employee.employeeId}, #{employee.name}, #{employee.phone},#{employee.salary})")
    int insertEmployee(@Param("employee") Employee employee);

    // 插入员工角色信息
    @Insert("INSERT INTO employee_has_role (employee_id, role_id, skill) VALUES (#{employeeId}, #{roleId}, #{skill})")
    int insertEmployeeHasRole(@Param("employeeId") String employeeId, @Param("roleId") String roleId, @Param("skill") String skill);

    // 通过员工ID获取账号的用户名
    @Select("SELECT username FROM account WHERE user_id = #{employeeId}")
    String selectUsernameByEmployeeId(@Param("employeeId") String employeeId);

    //更新员工信息
    @Update("UPDATE employee SET name = #{employee.name},phone = #{employee.phone},salary = #{employee.salary} WHERE employee_id = #{employee.employeeId}")
    int updateEmployee(@Param("employee") Employee employee);
}
